﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Diagnostics;
using framework.map;

namespace framework.ui
{
    public partial class Curve : Form
    {
        string current = "";
        public Curve()
        {
            InitializeComponent();
        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = "curve.exe";
            info.Arguments = CurveGen.generateArgs(Convert.ToInt32(numericUpDown1.Value),
                                                   Convert.ToInt32(numericUpDown2.Value),
                                                   Convert.ToInt32(numericUpDown5.Value),
                                                   Convert.ToInt32(numericUpDown6.Value),
                                                   Convert.ToInt32(numericUpDown8.Value)
                                                  );
            info.Arguments += "";
            info.UseShellExecute = false;
            info.RedirectStandardOutput = true;

            Process p = new Process();
            p.StartInfo = info;
            p.Start();
            this.toolStripStatusLabel1.Text = "generating...";
            current = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            this.toolStripStatusLabel1.Text = "Map has been successfully generated";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog s = new SaveFileDialog();

            s.Filter = "Mapcode (*.map)|*.map|All Files (*.*)|*.*";
            if(s.ShowDialog() == DialogResult.OK)
                File.WriteAllText(s.FileName, current);
        }

        private void groupBox2_Paint(object sender, PaintEventArgs e)
        {
            /*Graphics g = this.CreateGraphics();
            PointF[] outers = CurveLivePreview.getOuters(256f, 8, 0f, 180f);
            PointF[] inners = CurveLivePreview.getRadii(128f, 8, 0f, 180f);
            for (int i = 0; i < 8; i++)
            {
                g.DrawLine(Pens.Chocolate, outers[i], inners[i]);
                g.DrawLine(Pens.Chocolate, outers[i], outers[i + 1]);
                g.DrawLine(Pens.Chocolate, inners[i], inners[i + 1]);
            }*/
        }
    }
}
